package com.xiaohudie.SSGworket;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @Author xiao hu die
 * @Date 2022/3/27 18:32
 * @Version 1.0
 */
public class TcpTest {
 public static void main(String[] args) {
  Socket socket =null;
  OutputStream outputStream =null;
  try {
   InetAddress byName = InetAddress.getByName("127.0.0.1");
   socket =new Socket(byName,8899);
   outputStream = socket.getOutputStream();
   outputStream.write(("你好,我是客户端").getBytes());
  }catch (Exception e){
   e.printStackTrace();
  }finally {
   if (socket!=null){
    try {
     socket.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
   if (outputStream!=null){
    try {
     outputStream.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
 }
}
